/*
GANESHA - Reasoning on critical infrastructures affected by emergency situations
Copyright (c) 2008-2011, Information Eng. Research Unit - Univ. of Alcala
http://www.cc.uah.es/ie
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package es.uah.cc.ie.ganesha;

import es.uah.cc.ie.ganesha.messaging.AlertMessage;
import java.io.DataOutputStream;
import java.util.Hashtable;
import java.util.List;
import java.util.Observable;

/**
 *
 * @author msicilia
 */
public class SituationManager extends Observable {

    protected Hashtable<String, AlertMessage> _messages = null;

    /**
     * Constructor.
     */
    public SituationManager() {
        _messages = new Hashtable<String, AlertMessage>();
    }

    /**
     * Adds an alert message.
     * @param m Alert message to be added.
     */
    public void addUniqueIncident(AlertMessage m) {
        assert (m.isUnique());
        _messages.put(m.getIdentifier(), m);
    }

    /**
     * Adds a list of alert messages.
     * @param messages Messages to be added.
     */
    public void addIncidents(List<AlertMessage> messages) {
        for (AlertMessage message : messages) {
            _messages.put(message.getIdentifier(), message);
        }
    }

    /**
     * Closes the situation, so that its contents become freezed and it 
     * does not respond to any additional incoming messages.
     */
    public void close() {
    }

    /**
     * Returns the message list.
     * @return Message list.
     */
    public Hashtable<String, AlertMessage> getMessages() {
        return _messages;
    }

    /**
     * Precondition: isClosed()
     * @param o
     */
    public void dumpSituation(DataOutputStream o) {
    }

    /**
     * Creates a new AlertMessage according to the type of situations managed.
     * @param identifier Identifier of the new message.
     * @return The new message.
     */
    public AlertMessage newMessage(String identifier) {
        return new AlertMessage(identifier);
    }

    /**
     * Returns the descriptive domain from the non-descriptive domain.
     * @param domain Non-descriptive domain.
     * @return Descriptive domain.
     */
    public String getEventTypeFromDomain(String domain) {
        if (domain.equals("Electricity"))//RED ELECTRICA ESPANYOLA"))
        {
            return "TECNOLOGICO/INFRAESTRUCTURAS";///ELECTRICIDAD";
        } else if (domain.equals("Gas"))//ENAGAS"))
        {
            return "TECNOLOGICO/INFRAESTRUCTURAS";///GAS";
        }

        return "UNKNOWN";
    }
}
